package com.yuhong.springbootinit.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.yuhong.springbootinit.model.dto.analysis.*;
import com.yuhong.springbootinit.model.dto.interview.InterviewStatusCountDTO;
import com.yuhong.springbootinit.service.ApplicantService;
import com.yuhong.springbootinit.common.BaseResponse;
import com.yuhong.springbootinit.common.ResultUtils;
import com.yuhong.springbootinit.service.InterviewService;
import com.yuhong.springbootinit.service.PositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/analysis")
@Slf4j
public class DataAnalysisController {

    @Resource
    private PositionService positionService;

    @Resource
    private ApplicantService applicantService;

    @Resource
    private InterviewService interviewService;


    @GetMapping("/getLocationRatios")
    public BaseResponse<PositionLocationResponse> getLocationRatios(){

        return ResultUtils.success(positionService.getLocationRatios());

    }


    @GetMapping("/getStatusRatios")
    public BaseResponse<PositionStatusResponse> getStatusRatios(){

        return ResultUtils.success(positionService.getStatusRatios());

    }

    @GetMapping("/getSalaryRatios")
    public BaseResponse<PositionSalaryResponse> getSalaryRatios(){

        return ResultUtils.success(positionService.getSalaryRatios());

    }

    @GetMapping("/getTagRatios")
    public BaseResponse<PositionTagResponse> getTagRatios() throws JsonProcessingException {

        return ResultUtils.success(positionService.getTagRatios());

    }

    @GetMapping("/getApplicantBgRatios")
    public BaseResponse<ApplicantBgResponse> getApplicantBgRatio(){

        return ResultUtils.success(applicantService.getApplicantBgRatio());

    }

    @GetMapping("/getApplicantMajorRatios")
    public BaseResponse<ApplicantMajorResponse> getApplicantMajorRatio(){

        return ResultUtils.success(applicantService.getApplicantMajorRatio());

    }

    /**
     * 获取 status 为 1、2、3 的每个数量
     */
    @GetMapping("/count/test")
    public BaseResponse<List<InterviewStatusCountDTO>> countCreatedToTestedStatuses(@RequestParam String positionId) {
        List<InterviewStatusCountDTO> result = interviewService.countCreatedToTestedStatuses(positionId);
        return ResultUtils.success(result);
    }

    /**
     * 获取 status 为 1 到 5 的每个数量
     */
    @GetMapping("/count/exam")
    public BaseResponse<List<InterviewStatusCountDTO>> countStatusFrom1To5(@RequestParam  String positionId) {
        List<InterviewStatusCountDTO> result = interviewService.countStatusFrom1To5(positionId);
        return ResultUtils.success(result);
    }


}
